//
//  PersonalCenterController.m
//  ManageMoney
//
//  Created by epwk on 15/9/8.
//  Copyright (c) 2015年 db. All rights reserved.
//

#import "PersonalCenterController.h"
#import "AboutUsViewController.h"
#import "UserAgreementController.h"
#import "ServiceCenterController.h"
#import "UserShareController.h"
#import "zhuceViewController.h"
#import "CardManagement.h"
@interface PersonalCenterController ()
@property (weak, nonatomic) IBOutlet UIButton *aboutUsBtn;
@property (weak, nonatomic) IBOutlet UIButton *serviceBtn;
@property (weak, nonatomic) IBOutlet UIButton *protocolBtn;
@property (weak, nonatomic) IBOutlet UIButton *shareBtn;
@property (weak, nonatomic) IBOutlet UIButton *logoutBtn;
@property (weak, nonatomic) IBOutlet UIButton *certificationBtn;

@end

@implementation PersonalCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"用户中心";
}



- (IBAction)userCenterItemAction:(id)sender {
    UIButton *btn = (UIButton *)sender;
    switch (btn.tag) {
        case 0://关于我们
        {
            AboutUsViewController *ctr = [[AboutUsViewController alloc] initWithNibName:@"AboutUsViewController" bundle:nil];
            [self.navigationController pushViewController:ctr animated:YES];
        }
            break;
        case 1://客服中心
        {
            ServiceCenterController *ctr = [[ServiceCenterController alloc] initWithNibName:@"ServiceCenterController" bundle:nil];
            [self.navigationController pushViewController:ctr animated:YES];
        }
            break;
        case 2://用户协议
        {
            UserAgreementController *ctr = [[UserAgreementController alloc] initWithNibName:@"UserAgreementController" bundle:nil];
            [self.navigationController pushViewController:ctr animated:YES];
        }
            break;
        case 3://卡管理
        {
            CardManagement *CashCardCertification = [[CardManagement alloc]initWithNibName:@"CardManagement" bundle:nil];
            CashCardCertification.addCardStr = @"1";
            CashCardCertification.customerNoStr = CheckNull(UserInfo[@"customerNum"]);
            [self.navigationController pushViewController:CashCardCertification animated:YES];
        }
            break;
        case 4://身份认证
        {
            if (![[[UserDefaults objectForKey:kUserInfo] allKeys] containsObject:@"STATUS"] || [CheckNull(UserInfo[@"STATUS"]) isEqualToString:@""]) {
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您还未提交身份认证，请上传认证信息" preferredStyle:UIAlertControllerStyleAlert];
                
                // 添加按钮
                [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                    zhuceViewController *ctr = [[zhuceViewController alloc] initWithNibName:@"zhuceViewController" bundle:nil];
                    ctr.zhuceStr = CheckNull(UserInfo[@"NUMBER"]);
                    [self.navigationController pushViewController:ctr animated:YES];
                    
                }]];
                [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    NSLog(@"点击了取消按钮");
                }]];
                [self presentViewController:alert animated:YES completion:nil];
                
            }else if([CheckNull(UserInfo[@"STATUS"]) isEqualToString:@"0"]){
                
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您提交的身份认证正在审核中，请稍后" preferredStyle:UIAlertControllerStyleAlert];
                
                // 添加按钮
                [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                    
                }]];
                [self presentViewController:alert animated:YES completion:nil];
                
            }else if([CheckNull(UserInfo[@"STATUS"]) isEqualToString:@"1"]){
                
                UserShareController *ctr = [[UserShareController alloc] initWithNibName:@"UserShareController" bundle:nil];
                //                ctr.zhuceStr = CheckNull(UserInfo[@"NUMBER"]);
                [self.navigationController pushViewController:ctr animated:YES];
                
            }else if([CheckNull(UserInfo[@"STATUS"]) isEqualToString:@"2"]){
                UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您未通过身份认证，请重新上传认证信息" preferredStyle:UIAlertControllerStyleAlert];
                
                // 添加按钮
                [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
                    zhuceViewController *ctr = [[zhuceViewController alloc] initWithNibName:@"zhuceViewController" bundle:nil];
                    ctr.zhuceStr = CheckNull(UserInfo[@"NUMBER"]);
                    [self.navigationController pushViewController:ctr animated:YES];
                    
                }]];
                [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    NSLog(@"点击了取消按钮");
                }]];
                [self presentViewController:alert animated:YES completion:nil];
            }
            

            
            
            
        }
            break;
        case 5://用户退出
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:RefreshUserData object:nil];
            
            [UserDefaults setObject:nil forKey:kUserInfo];
            [UserDefaults setBool:NO forKey:kDidLogin];
            [UserDefaults synchronize];
            
            [self leftBarButtonClick:nil];
            
            [SVProgressHUD showSuccessWithStatus:@"退出成功"];
            
            
        }
            break;
            
        default:
            break;
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
